/**
 * Copyright (c) 2018-2024, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 * 
 * Contains: device tree from xboot
 * 
 * Change Logs:
 * Date           Author            Notes
 * 2024-1-4       JasonHu           Init
 */

#ifndef __DTREE_H__
#define __DTREE_H__

#include <nx_configure.h>

#ifdef CONFIG_NX_DEVICE_TREE_SUPPORT
#include <base/json.h>

typedef struct DT_Node {
	const char * name;
	int id;
	NX_Addr addr;
	struct JSON_Value * value;
} DT_Node;

const char * DT_ReadName(DT_Node * n);
int DT_ReadID(DT_Node * n);
NX_Addr DT_ReadAddress(DT_Node * n);
int DT_ReadBool(DT_Node * n, const char * name, int def);
int DT_ReadInt(DT_Node * n, const char * name, int def);
NX_UArch DT_ReadLong(DT_Node * n, const char * name, NX_UArch def);
double DT_ReadDouble(DT_Node * n, const char * name, double def);
char * DT_ReadString(DT_Node * n, const char * name, char * def);
NX_U8 DT_ReadU8(DT_Node * n, const char * name, NX_U8 def);
NX_U16 DT_ReadU16(DT_Node * n, const char * name, NX_U16 def);
NX_U32 DT_ReadU32(DT_Node * n, const char * name, NX_U32 def);
NX_U64 DT_ReadU64(DT_Node * n, const char * name, NX_U64 def);
DT_Node * DT_ReadObject(DT_Node * n, const char * name, DT_Node * o);

int DT_ReadArrayLength(DT_Node * n, const char * name);
int DT_ReadArrayBool(DT_Node * n, const char * name, int idx, int def);
int DT_ReadArrayInt(DT_Node * n, const char * name, int idx, int def);
NX_UArch DT_ReadArrayLong(DT_Node * n, const char * name, int idx, NX_UArch def);
double DT_ReadArrayDouble(DT_Node * n, const char * name, int idx, double def);
char * DT_ReadArrayString(DT_Node * n, const char * name, int idx, char * def);
NX_U8 DT_ReadArrayU8(DT_Node * n, const char * name, int idx, NX_U8 def);
NX_U16 DT_ReadArrayU16(DT_Node * n, const char * name, int idx, NX_U16 def);
NX_U32 DT_ReadArrayU32(DT_Node * n, const char * name, int idx, NX_U32 def);
NX_U64 DT_ReadArrayU64(DT_Node * n, const char * name, int idx, NX_U64 def);
DT_Node * DT_ReadArrayObject(DT_Node * n, const char * name, int idx, DT_Node * o);
#endif

#endif /* __DTREE_H__ */
